package com.example.androiduidemo2;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;

import androidx.appcompat.app.AppCompatActivity;


import com.example.androiduidemo2.Adapter.CourseArrayAdapter;
import com.example.androiduidemo2.database.CourseMessage;
import com.example.androiduidemo2.entity.Course;

import java.util.List;

public class CourseActivity extends AppCompatActivity {
    private ListView listView;
    private CourseMessage dbHelper;
    private List<Course> courses;
    private CourseArrayAdapter courseArrayAdapter;
    private Button buttonStudents,buttonCourses,buttonProfile;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_course);

        dbHelper = new CourseMessage(this);
        listView = findViewById(R.id.course_list);




        buttonStudents = findViewById(R.id.buttonStudents);
        buttonStudents.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent courseIntent = new Intent(CourseActivity.this,StudentActivity.class);
                startActivity(courseIntent);
            }
        });




        buttonProfile = findViewById(R.id.buttonProfile);
        buttonProfile.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent courseIntent = new Intent(CourseActivity.this,InformationActivity.class);
                startActivity(courseIntent);
            }
        });





        // 获取所有课程信息
        courses = dbHelper.getAllCourses();
        courseArrayAdapter = new CourseArrayAdapter(this, courses);
        listView.setAdapter(courseArrayAdapter);
    }

}
